package com.haixiaoke.service.impl;

import java.util.List;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.haixiaoke.common.utils.DateUtils;
import com.haixiaoke.domain.SmartLock;
import com.haixiaoke.domain.SmartLockFingerprint;
import com.haixiaoke.mapper.SmartLockFingerprintMapper;
import com.haixiaoke.service.ISmartLockFingerprintService;
import com.haixiaoke.smartLock.tianwanghulian.SmartLockTWHlService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 智能锁指纹授权信息Service业务层处理
 *
 * @author xiaolong
 * @date 2023-05-27
 */
@Service
public class SmartLockFingerprintServiceImpl implements ISmartLockFingerprintService {
    @Autowired
    private SmartLockFingerprintMapper smartLockFingerprintMapper;
    @Autowired
    private SmartLockTWHlService smartLockTWHlService;

    /**
     * 查询智能锁指纹授权信息
     *
     * @param fingerprintId 智能锁指纹授权信息主键
     * @return 智能锁指纹授权信息
     */
    @Override
    public SmartLockFingerprint selectSmartLockFingerprintByFingerprintId(Long fingerprintId) {
        return smartLockFingerprintMapper.selectSmartLockFingerprintByFingerprintId(fingerprintId);
    }

    /**
     * 查询智能锁指纹授权信息列表
     *
     * @param smartLockFingerprint 智能锁指纹授权信息
     * @return 智能锁指纹授权信息
     */
    @Override
    public List<SmartLockFingerprint> selectSmartLockFingerprintList(SmartLockFingerprint smartLockFingerprint) {
        return smartLockFingerprintMapper.selectSmartLockFingerprintList(smartLockFingerprint);
    }

    /**
     * 新增智能锁指纹授权信息和授权指纹
     *
     * @param smartLockFingerprint 智能锁指纹授权信息
     * @return 结果
     */
    @Override
    public int insertSmartLockFingerprint(SmartLockFingerprint smartLockFingerprint) {
        smartLockFingerprint.setCreateTime(DateUtils.getNowDate());
        return smartLockFingerprintMapper.insertSmartLockFingerprint(smartLockFingerprint);
    }

    /**
     * 修改智能锁指纹授权信息和下发指纹信息
     *
     * @param smartLockFingerprint 智能锁指纹授权信息
     * @return 结果
     */
    @Override
    public int updateSmartLockFingerprint(SmartLockFingerprint smartLockFingerprint) {
        smartLockFingerprint.setUpdateTime(DateUtils.getNowDate());
        return smartLockFingerprintMapper.updateSmartLockFingerprint(smartLockFingerprint);
    }

    /**
     * 批量删除智能锁指纹授权信息和删除指纹授权信息
     *
     * @param fingerprintId 需要删除的智能锁指纹授权信息主键
     * @return 结果
     */
    @Override
    public int deleteSmartLockFingerprintByFingerprintIds(Long fingerprintId) {
        return smartLockFingerprintMapper.deleteSmartLockFingerprintByFingerprintId(fingerprintId);
    }

    /**
     * 删除智能锁指纹授权信息信息
     *
     * @param fingerprintId 智能锁指纹授权信息主键
     * @return 结果
     */
    @Override
    public int deleteSmartLockFingerprintByFingerprintId(Long fingerprintId) {
        return smartLockFingerprintMapper.deleteSmartLockFingerprintByFingerprintId(fingerprintId);
    }

    @Override
    public int deleteSmartLockFingerprintByLockSNAndIdentification(String sn, String identification) {
        return smartLockFingerprintMapper.deleteSmartLockFingerprintByLockSNAndIdentification(sn, identification);
    }

    public int deleteSmartLockFingerprintBySn(String sn) {
        return smartLockFingerprintMapper.deleteSmartLockFingerprintBySn(sn);
    }

    public int deleteSmartLockFingerprintByEndTime(DateTime date) {
        return smartLockFingerprintMapper.deleteSmartLockFingerprintByEndTime(date);
    }
}
